<?php
class Response
{
    // CONTENT TYPE
    const JSON = 'application/json';
    const HTML = 'text/html';
    const JAVASCRIPT = 'text/javascript';
    const JS   = 'text/javascript';
    const TEXT = 'text/plain';
    const XML  = 'text/xml';

    static public $response_type = null;

    static public function JSON($data = array(), $content_type = Response::JSON)
    {
        self::$response_type = Response::JSON;

		if($content_type!==null){
			header("Content-type: " . $content_type);
		}

        if (is_object($data))
            $data = get_object_vars($data);
        else if (! is_array($data))
            $data = array();

        return htmlspecialchars(json_encode($data), ENT_NOQUOTES);
    }

    static public function HTML($data = array(), $content_type = Response::JSON)
    {
        self::$response_type = Response::HTML;

        header("Content-type: " . $content_type);

        if (is_object($data))
            $data = get_object_vars($data);
        else if (! is_array($data))
            $data = array();
        
        return json_encode($data);
    }

    static public function STRING($data = '')
    {
        echo $data;
        exit;
    }
}

?>